using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AntEater.Runtime.Services.Transformation;
using System.Xml.XPath;
using AntEater.ComponentModel.BuildElements;
using System.IO;

namespace AntEater.Runtime.Tests.Services.Transformation
{
    /// <summary>
    /// Summary description for XmlToBuildElementTransformationServiceTest
    /// </summary>
    [TestClass]
    public class XmlToBuildElementTransformationServiceTest
    {

        public const string BuildFilePath = "..\\..\\..\\..\\UnitTests\\TestData\\BuildFiles\\AntEater.ComponentModel.csproj.xml";
        //public const string BuildFilePath = "..\\..\\..\\..\\UnitTests\\TestData\\BuildFiles\\SampleBuildFile.build";

        private XmlToBuildElementTransformationService _service;

        /// <summary>
        /// Gets or sets the service.
        /// </summary>
        /// <value>The service.</value>
        private XmlToBuildElementTransformationService Service
        {
            get { return _service; }
            set { _service = value; }
        }

        private Stream _buildFile;

        /// <summary>
        /// Gets or sets the build file.
        /// </summary>
        /// <value>The build file.</value>
        private Stream BuildFile
        {
            get { return _buildFile; }
            set { _buildFile = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:XmlToBuildElementTransformationServiceTest"/> class.
        /// </summary>
        public XmlToBuildElementTransformationServiceTest()
        {
            this._service = new XmlToBuildElementTransformationService();
            this._buildFile = File.OpenRead(BuildFilePath);

        }

        /// <summary>
        /// Transforms the XML to build element test.
        /// </summary>
        [TestMethod]
        public void TransformXmlToBuildElementTest()
        {
            XmlToBuildElementTransformationResult transformationResult
                = this.Service.Transform(this.BuildFile, BuildFilePath);

            Assert.IsNotNull(transformationResult, "Result is null.");
            Assert.IsNotNull(transformationResult.BuildFileDefinition, "BuildFileDefinition is null.");
            Assert.IsNotNull(transformationResult.Errors, "Errors is null.");

            Console.Write(Utilities.DumpBuildComponentTree(transformationResult.BuildFileDefinition.RootBuildElement.ChildElements));

            Assert.IsTrue(transformationResult.BuildFileDefinition.RootBuildElement.ChildElements.Count > 0, "No elements transformed.");
            Assert.IsTrue(transformationResult.Errors.Count == 0, "{0} errors occured.",transformationResult.Errors.Count);
        }
    }
}
